//
//  ViewController.m
//  Class- 点击cell展开
//
//  Created by XHmacbook on 17/6/6.
//  Copyright © 2017年 macbook. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()<UITableViewDelegate,UITableViewDataSource>{
    
    NSMutableArray *arr;
}
@property (nonatomic,strong)UITableView *myTable;
@property (nonatomic,strong)UIButton *butt;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
  
    
    [self.view addSubview:self.myTable];
    arr = [NSMutableArray array];
    for (int i = 0; i < 3; i++) {
        self.butt = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 44)];
        self.butt.backgroundColor = [UIColor greenColor];
        [self.butt setTitle:@"是发放" forState:UIControlStateNormal];
        [self.butt setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
        [self.butt addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
        
        self.butt.tag = i;
        
        [arr addObject:self.butt];

    }


}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 5;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return 3;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    
      cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
//
    if (indexPath.section == 3) {
  
        [cell addSubview:arr[indexPath.row]];
        
    }
//
    
    return cell;
    
}


-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    UIButton *button = arr[indexPath.row];

    if (button.selected == YES&&indexPath.section == 3) {
        return 210;
    }
    return 44;
}
-(void)click:(UIButton*)senter{
    
    senter.selected = !senter.selected;
    if (senter.selected) {
        
    }
    [self.myTable reloadData];
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(UITableView *)myTable{
    
    if (!_myTable) {
        _myTable = [[UITableView alloc]initWithFrame:self.view.frame style:UITableViewStyleGrouped];
        _myTable.delegate = self;
        _myTable.dataSource = self;

    }
    return _myTable;
}

@end
